﻿using System;
using System.Collections.Generic;

namespace Microsoft.Popfly.GameCreator.GameEngine.Behaviors
{
    public class PropertySetBehavior : IBehavior
    {
        private PropertyHolder m_propertyHolder;
        private String m_propertyName;
        private Object m_value;

        public PropertySetBehavior(PropertyHolder propHolder,
                                   String propName,
                                   Object value)
        {
            m_propertyHolder = propHolder;
            m_propertyName = propName;
            m_value = value;
        }

        #region IBehavior Members

        public void Invoke(BehaviorOwner sender, Microsoft.Popfly.GameCreator.GameEngine.Events.PGCEventArgs args)
        {
            m_propertyHolder.SetValue(m_propertyName, m_value);
        }

        #endregion
    }

    public class PropertySetsBehavior : IBehavior
    {
        private Game m_game;
        private String m_actorName;
        private String m_propertyName;
        private Object m_value;
        private BehaviorOwner m_owner;


        public PropertySetsBehavior(Game game,
                                    BehaviorOwner owner,
                                    String actorClassName,
                                    String propName,
                                    Object value)
        {
            m_game = game;
            m_owner = owner;
            m_actorName = actorClassName;
            m_propertyName = propName;
            m_value = value;
        }

        #region IBehavior Members

        public void Invoke(BehaviorOwner sender, Microsoft.Popfly.GameCreator.GameEngine.Events.PGCEventArgs args)
        {
            List<Actor> propertyHolders = m_owner.Scene.GetActors(m_actorName);
            foreach (Actor propertyHolder in propertyHolders)
            {
                propertyHolder.SetValue(m_propertyName, m_value);
            }
        }

        #endregion
    }
}
